In [ ]:
import numpy as np
from bqplot import *
In [ ]:
size = 100
scale = 100.
np.random.seed(0)
x_data = np.arange(size)
y_data = np.cumsum(np.random.randn(size) * scale)
In [ ]:
x_sc = LinearScale()
y_sc = LinearScale()
ax_x = Axis(label='X', scale=x_sc, grid_lines='solid')
ax_y = Axis(label='Y', scale=y_sc, orientation='vertical', grid_lines='solid')
line = Lines(x=x_data, y=x_data, scales={'x': x_sc, 'y': y_sc})
fig = Figure(axes=[ax_x, ax_y], marks=[line], title='First Example')
fig
This image can be saved by calling the save_png
function of the Figure
object:
In [ ]:
fig.save_png()
In [ ]:
dates = np.arange('2005-02', '2005-03', dtype='datetime64[D]')
size = len(dates)
prices = scale + 5 * np.cumsum(np.random.randn(size))
In [ ]:
dt_x = DateScale()
lin_y = LinearScale()
x_ax = Axis(label='Date', scale=dt_x, tick_format='%b-%d', grid_lines='solid')
x_ay = Axis(label=('Price'), scale=lin_y, orientation='vertical', tick_format='0.0f', grid_lines='solid')
lc = Lines(x=dates, y=prices, scales={'x': dt_x, 'y': lin_y}, colors=['blue'])
fig = Figure(marks=[lc], axes=[x_ax, x_ay], background_style={'fill': 'lightgreen'},
title_style={'font-size': '20px','fill': 'DarkOrange'}, title='Changing Styles')
fig
In [ ]:
fig.background_style = {'fill': 'Black'}
In [ ]:
sc_x = LinearScale()
sc_y = LinearScale()
scatter = Scatter(x=x_data, y=y_data, scales={'x': sc_x, 'y': sc_y}, colors=['blue'])
ax_x = Axis(label='Test X', scale=sc_x)
ax_y = Axis(label='Test Y', scale=sc_y, orientation='vertical', tick_format='0.2f')
Figure(axes=[ax_x, ax_y], marks=[scatter])
In [ ]:
scale_x = LinearScale()
scale_y = LinearScale()
hist = Hist(sample=y_data, scales={'sample': scale_x, 'count': scale_y})
ax_x = Axis(label='X', scale=scale_x, tick_format='0.2f')
ax_y = Axis(label='Y', scale=scale_y, orientation='vertical', grid_lines='solid')
Figure(axes=[ax_x, ax_y], marks=[hist])
In [ ]:
sc_x1 = OrdinalScale()
sc_y1 = LinearScale()
bar_x = Axis(label='X', scale=sc_x1)
bar_y = Axis(label='Y', scale=sc_y1, orientation='vertical', tick_format='0.0f', grid_lines='solid')
bar_chart = Bars(x=['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U'],
y=np.abs(y_data[:20]), scales={'x': sc_x1, 'y': sc_y1})
Figure(axes=[bar_x, bar_y], marks=[bar_chart], padding_x=0)